package Hot100;

import java.util.HashMap;

public class lengthOfLongestSubstring {
    public static void main(String[] args) {
        lengthOfLongestSubstring lengthOfLongestSubstring = new lengthOfLongestSubstring();
        String s = "dvdf";
        System.out.println(lengthOfLongestSubstring.lengthOfLongestSubstring(s));

    }
    public int lengthOfLongestSubstring(String s) {
        HashMap hashMap = new HashMap();
        char[] arrays = s.toCharArray();
        int temp = 0;
        int all = 0;
        for (int i = 0; i < arrays.length; i++) {
            if(!hashMap.containsKey(arrays[i])){
                temp++;
                hashMap.put(arrays[i],i);
                if(temp > all)
                    all = temp;
            }else {
                temp = 0;
                int value = (int) hashMap.get(arrays[i]);
                hashMap.clear();
                i = value ;
            }
        }
        return all;
    }
}
